package com.rdc.qingkou.presenter;

import android.util.Log;

import com.rdc.qingkou.contract.SubscribeContract;
import com.rdc.qingkou.entity.SubscribeListResult;
import com.rdc.qingkou.entity.SubscribeUserResult;
import com.rdc.qingkou.model.SubscribeModel;
import com.rdc.qingkou.model.imodel.OnHttpCallBack;



public class SubscribePresenter implements SubscribeContract.ISubscribePresenter{

    SubscribeContract.ISubscribeModel mISubscribeModel;
    SubscribeContract.ISubscribeView mISubscribeView;

    public SubscribePresenter(SubscribeContract.ISubscribeView mISubscribeView){
        this.mISubscribeView = mISubscribeView;
        mISubscribeModel = new SubscribeModel();
    }

    @Override
    public void getUnReadNewsNum() {

    }

    @Override
    public void getMessage() {

    }

    @Override
    public void loadMoreMessage() {

    }

    /**
     * 关注/订阅(取消也是这个接口)
     *
     * @param userId
     * @param subscribeId
     */
    @Override
    public void subscribeUser(Integer userId, Integer subscribeId) {

        mISubscribeView.showProgress();   //通知V层显示对话框

        mISubscribeModel.subscribeUser(userId,subscribeId,new OnHttpCallBack<SubscribeUserResult>() {



            @Override
            public void onSuccessful(SubscribeUserResult result) {

                Log.d("SubscribePresenter","onSuccessful");
                mISubscribeView.hideProgress();
                mISubscribeView.subscribeUser(result);

            }

            @Override
            public void onFaild(String errorMsg) {

                Log.d("SubscribePresenter","onFaild");

                mISubscribeView.hideProgress();  //通知V层隐藏对话框
                mISubscribeView.showInfo(errorMsg);   //通知V层显示错误信息

            }
        });
    }

    /**
     *获取指定用户的关注列表
     *
     * @param userId
     */
    @Override
    public void getSubscribeList(Integer userId) {

        mISubscribeView.showProgress();   //通知V层显示对话框

          mISubscribeModel.getSubscribeList(userId,new OnHttpCallBack<SubscribeListResult>() {


        //有一个请求结果的回调,即我调用请求电影信息的方法了,M层要返回一个成功还是失败的信息给我

            @Override
            public void onSuccessful(SubscribeListResult result) {



                Log.d("MessagePresenter","onSuccessful");
                mISubscribeView.hideProgress();
                mISubscribeView.showSubscribeList(result);

            }

            @Override
            public void onFaild(String errorMsg) {

                Log.d("MessagePresenter","onFaild");

                mISubscribeView.hideProgress();  //通知V层隐藏对话框
                mISubscribeView.showInfo(errorMsg);   //通知V层显示错误信息

            }
        });
    }

    /**
     *获取指定用户的粉丝列表
     *
     * @param userId
     */
    @Override
    public void getFansList(Integer userId) {

        mISubscribeView.showProgress();   //通知V层显示对话框

//        mISubscribeModel.getFansList(userId,new OnHttpCallBack<SubscribeResult<SubscribeResult.subscribeListBean>>() {
//        mISubscribeModel.getFansList(userId,new OnHttpCallBack<SubscribeResult<List<User>>>() {
        mISubscribeModel.getFansList(userId,new OnHttpCallBack<SubscribeListResult>() {


            //有一个请求结果的回调,即我调用请求电影信息的方法了,M层要返回一个成功还是失败的信息给我

            @Override
            public void onSuccessful(SubscribeListResult result) {

                Log.d("MessagePresenter","onSuccessful");
                mISubscribeView.hideProgress();
                mISubscribeView.showFansList(result);

            }

            @Override
            public void onFaild(String errorMsg) {

                Log.d("MessagePresenter","onFaild");

                mISubscribeView.hideProgress();  //通知V层隐藏对话框
                mISubscribeView.showInfo(errorMsg);   //通知V层显示错误信息

            }
        });

    }
}
